import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login.vue'
import Layout from '@/views/Layout.vue'
import Dashboard from '@/views/Dashboard.vue'
import LotteryData from '@/views/LotteryData.vue'
import AIAnalysis from '@/views/AIAnalysis.vue'
import Reports from '@/views/Reports.vue'
import store from '@/store'

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: { requiresAuth: false }
  },
  {
    path: '/',
    component: Layout,
    meta: { requiresAuth: true },
    children: [
      {
        path: '',
        name: 'Dashboard',
        component: Dashboard
      },
      {
        path: 'lottery',
        name: 'LotteryData',
        component: LotteryData
      },
      {
        path: 'ai-analysis',
        name: 'AIAnalysis',
        component: AIAnalysis
      },
      {
        path: 'reports',
        name: 'Reports',
        component: Reports
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.meta.requiresAuth && !store.getters.isAuthenticated) {
    next('/login')
  } else {
    next()
  }
})

export default router 